import json

import requests

from config.environment import webhook


def send_to_dingding(webhook, message):
    headers = {
        "Content-type": "application/json",
        "Charset": "UTF-8"
    }
    data = {
        "msgtype": "text",
        "text": {
            "content": message
        }
    }
    response = requests.post(webhook, headers=headers, data=json.dumps(data))
    if response.status_code == 200:
        print("消息发送成功")
    else:
        print(f"消息发送失败{response.text}")


if __name__ == '__main__':
    send_to_dingding(webhook=webhook, message="leopold测试")
